'''
商机页面
'''

from selenium.webdriver.common.by import By
from page.base_page import BasePage

class SjPage(BasePage):
    url="/crm/index.php?m=business"

    #定位器
    btn_add_sj_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")
    btn_cat_sj_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(12) > a:nth-child(1)")
    first_select_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    del_locator = (By.ID, "delete")
    first_sj_name_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(4) > a > span")
    btn_chargeme_locator = (By.LINK_TEXT, "我负责的")
    first_sj_charge_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(1) > td:nth-child(8) > a")
    btn_chargeunderling_locator = (By.LINK_TEXT, "下属负责")
    btn_createme_locator = (By.LINK_TEXT, "我创建的")
    first_sj_create_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(1) > td:nth-child(9) > a")
    first_sj_contact_time_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr > td:nth-child(6) > span")
    btn_createunderling_locator = (By.LINK_TEXT, "下属创建的")
    btn_contacttoday_locator = (By.LINK_TEXT, "今日需联系")
    btn_contactthisweek_locator = (By.LINK_TEXT, "本周需联系")
    btn_contactthismonth_locator = (By.LINK_TEXT, "本月需联系")
    btn_uncontact7_locator = (By.LINK_TEXT, "7日未联系")
    btn_uncontact15_locator = (By.LINK_TEXT, "15日未联系")
    btn_uncontact30_locator = (By.LINK_TEXT, "30日未联系")
    btn_recent_create_locator = (By.LINK_TEXT, "最近创建")
    btn_recent_update_locator = (By.LINK_TEXT, "最近更新")
    btn_trash_locator = (By.CSS_SELECTOR, "body > div.container > p > a:nth-child(17)")

    def click_add_sj(self):
        '''点击添加商机'''
        self.driver.find_element(*self.btn_add_sj_locator).click()
    def click_cat_sj(self):
        '''点击查看按钮'''
        self.driver.find_element(*self.btn_cat_sj_locator).click()
    def click_first_select(self):
        '''点击商机列表中的第一个商机前面的选择框'''
        self.driver.find_element(*self.first_select_locator).click()
    def click_del(self):
        '''点击删除按钮'''
        self.driver.find_element(*self.del_locator).click()
    def accept_del(self):
        '''确认删除操作'''
        self.driver.switch_to.alert.accept()

    def get_first_sj_name(self):
        '''获取商机列表第一个商机的商机名'''
        return self.driver.find_element(*self.first_sj_name_locator).text.strip()

    def click_chargeme(self):
        '''点击我负责的'''
        self.driver.find_element(*self.btn_chargeme_locator).click()
    def get_first_sj_charge(self):
        '''获取商机列表中第一个商机的负责人'''
        return self.driver.find_element(*self.first_sj_charge_locator).text.strip()
    def click_chargeunderling(self):
        '''点击下属负责'''
        self.driver.find_element(*self.btn_chargeunderling_locator).click()
    def click_createme(self):
        '''点击我创建的'''
        self.driver.find_element(*self.btn_createme_locator).click()
    def get_first_sj_create(self):
        '''获取商机列表中第一个商机的创建人'''
        return self.driver.find_element(*self.first_sj_create_locator).text.strip()
    def click_createunderling(self):
        '''点击下属创建的'''
        self.driver.find_element(*self.btn_createunderling_locator).click()
    def click_contacttoday(self):
        '''点击今日需联系'''
        self.driver.find_element(*self.btn_contacttoday_locator).click()
    def get_first_sj_contact_time(self):
        '''获取列表中第一个商机的下次联系时间'''
        return self.driver.find_element(*self.first_sj_contact_time_locator).text.strip()
    def click_contactthisweek(self):
        '''点击本周需联系'''
        self.driver.find_element(*self.btn_contactthisweek_locator).click()
    def click_contactthismonth(self):
        '''点击本月需联系'''
        self.driver.find_element(*self.btn_contactthismonth_locator).click()
    def click_uncontact7(self):
        '''点击7日未联系'''
        self.driver.find_element(*self.btn_uncontact7_locator).click()
    def click_uncontact15(self):
        '''点击15日未联系'''
        self.driver.find_element(*self.btn_uncontact15_locator).click()
    def click_uncontact30(self):
        '''点击30日未联系'''
        self.driver.find_element(*self.btn_uncontact30_locator).click()
    def click_recent_create(self):
        '''点击最近创建'''
        self.driver.find_element(*self.btn_recent_create_locator).click()
    def click_recent_update(self):
        '''点击最近更新'''
        self.driver.find_element(*self.btn_recent_update_locator).click()

